﻿Imports System.Data.SqlClient
Public Class ThemSinhVien

    Private _p1 As Object

    Sub New(ByVal p1 As Object)
        ' TODO: Complete member initialization 
        _p1 = p1
    End Sub

    Sub New()
        ' TODO: Complete member initialization 
    End Sub

    Private Property hinhanh As String

    Private Sub button2_Click(sender As System.Object, e As System.EventArgs) Handles button2.Click
        MessageBox.Show("CẬP NHẬT DỮ LIỆU THÀNH CÔNG")
        Me.Close()
        Dim frm As New ThemSinhVien(Lop_ID)
        frm.Show()
    End Sub

    Private Sub button1_Click(sender As System.Object, e As System.EventArgs) Handles button1.Click
        Me.Close()
        Dim frm As DanhSachSinhVien = New DanhSachSinhVien(Lop_ID)
        frm.Show()

    End Sub

    Private Sub button3_Click(sender As System.Object, e As System.EventArgs) Handles button3.Click
        Dim sex As Integer

        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        Dim TenLop As String
        TenLop = cbxTenLop.SelectedItem.ToString()
        cmd.CommandText = "select* from Lop where TenLop ='" + TenLop + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Dim MaLop As String = td.Rows(0)(0).ToString()
        If radioButton7.Checked = True Then
            sex = 0
        Else
            sex = 1
        End If

        cmd.CommandText = "INSERT INTO SinhVien VALUES('" + txtmaSV.Text + "','" + txtTenSV.Text + "'," + sex + ",'" + mskNgaySinh.Text + "','" + txtNoiS.Text + "','" + txtTT.Text + "','" + txtKH.Text + "','" + txtLL.Text + "','" + MaLop + "','" + hinhanh + "')"
        cmd.ExecuteNonQuery()
        con.Close()
        Dim strmasv As String
        Dim strtensv As String
        strtensv = txtTenSV.Text
        strmasv = txtmaSV.Text
        Dim frm As New ThemKetQua(strmasv, strtensv)
        frm.Show()
    End Sub

    Private Sub button4_Click(sender As System.Object, e As System.EventArgs) Handles button4.Click
        Dim dl As OpenFileDialog = New OpenFileDialog()
        dl.InitialDirectory = Application.StartupPath + "hinhanh/"
        If dl.ShowDialog() = DialogResult.OK Then
            hinhanh = dl.FileName.Substring(dl.FileName.LastIndexOf("\\") + 1, dl.FileName.Length - dl.FileName.LastIndexOf("\\") - 1)
            pictureBox1.Image = New Bitmap(Application.StartupPath + "\hinhanh\" + hinhanh)
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        End If
    End Sub

    Private Function Lop_ID() As Object
        Throw New NotImplementedException
    End Function

End Class